package org.persistente.esquema;

import java.lang.reflect.Field;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * Relação atributo-campo do tipo DOUBLE ou NUMERIC.
 */
public class CampoDouble extends CampoAbstrato<Double> {

    public CampoDouble(Field campo) {
        super(campo);
    }

    

    @Override
    public Double get(ResultSet rs) throws SQLException {
        double val = rs.getDouble(getNome());
        if (rs.wasNull()) {
            return null;
        }
        return val;
    }


    @Override
    public void set(PreparedStatement ps, int ind, Double valor) throws SQLException {
        if (valor != null) {
            ps.setDouble(ind, valor);
        } else {
            ps.setNull(ind, 2); //2: tipo SQL
        }
    }

}
